package com.startech.controller;

import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.startech.common.domain.vo.Result;
import com.startech.domain.HeatMap;
import com.startech.domain.LearnGoal;
import com.startech.domain.UserStatics;
import com.startech.service.IHeatMapService;
import com.startech.service.ILearnGoalService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "dashboard相关接口")
@RequiredArgsConstructor
@RestController
@RequestMapping("/progress")
public class ProgressController {
    private final IHeatMapService heatMapService;
    private final ILearnGoalService learnGoalService;
    @GetMapping("/dashboard")
    public Result getDashboard(Integer userId)
    {
        UserStatics one = Db.lambdaQuery(UserStatics.class)
                .eq(UserStatics::getUserId, userId)
                .one();
        return Result.success(one);
    }

    @GetMapping("/heatMap")
    public Result getHeatMap(Integer userId){
//        List<List<HeatMap>> heatMaps=new ArrayList<>();
        List<List<Float>> heatMaps=new ArrayList<>();
        for (int i = 1;i<=5;i++){
            List<HeatMap> list = Db.lambdaQuery(HeatMap.class)
                    .eq(HeatMap::getUserId, userId)
                    .eq(HeatMap::getMainTypeId, i)
                    .list();
            List<Float> accountList=new ArrayList<>();
            list.forEach(heatMap -> {
                Float account = heatMap.getAccount();
                accountList.add(account);
            });
            heatMaps.add(accountList);
        }

        return Result.success(heatMaps);
    }

    @GetMapping("/learnGoal")
    public Result getLearnGoal(Integer userId){
        LearnGoal learn = Db.lambdaQuery(LearnGoal.class)
                .eq(LearnGoal::getUserId, userId)
                .one();
        return Result.success(learn);
    }


}
